<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>richremotearraymatcher.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_ac_richremotearraymatcher.js.html">richremotearraymatcher.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Class that retrieves rich autocomplete matches, represented as
<a name="line17"></a> * a structured list of lists, via an ajax call.  The first element of each
<a name="line18"></a> * sublist is the name of a client-side javascript function that converts the
<a name="line19"></a> * remaining sublist elements into rich rows.
<a name="line20"></a> *
<a name="line21"></a> */
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.ui.ac.RichRemoteArrayMatcher&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.json&#39;);
<a name="line26"></a>goog.require(&#39;goog.ui.ac.RemoteArrayMatcher&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * An array matcher that requests rich matches via ajax and converts them into
<a name="line32"></a> * rich rows.
<a name="line33"></a> * @param {string} url The Uri which generates the auto complete matches.  The
<a name="line34"></a> *     search term is passed to the server as the &#39;token&#39; query param.
<a name="line35"></a> * @param {boolean=} opt_noSimilar If true, request that the server does not do
<a name="line36"></a> *     similarity matches for the input token against the dictionary.
<a name="line37"></a> *     The value is sent to the server as the &#39;use_similar&#39; query param which is
<a name="line38"></a> *     either &quot;1&quot; (opt_noSimilar==false) or &quot;0&quot; (opt_noSimilar==true).
<a name="line39"></a> * @constructor
<a name="line40"></a> * @extends {goog.ui.ac.RemoteArrayMatcher}
<a name="line41"></a> */
<a name="line42"></a>goog.ui.ac.RichRemoteArrayMatcher = function(url, opt_noSimilar) {
<a name="line43"></a>  goog.ui.ac.RemoteArrayMatcher.call(this, url, opt_noSimilar);
<a name="line44"></a>
<a name="line45"></a>  /**
<a name="line46"></a>   * A function(rows) that is called before the array matches are returned.
<a name="line47"></a>   * It runs client-side and filters the results given by the server before
<a name="line48"></a>   * being rendered by the client.
<a name="line49"></a>   * @type {Function}
<a name="line50"></a>   * @private
<a name="line51"></a>   */
<a name="line52"></a>  this.rowFilter_ = null;
<a name="line53"></a>
<a name="line54"></a>};
<a name="line55"></a>goog.inherits(goog.ui.ac.RichRemoteArrayMatcher, goog.ui.ac.RemoteArrayMatcher);
<a name="line56"></a>
<a name="line57"></a>
<a name="line58"></a>/**
<a name="line59"></a> * Set the filter that is called before the array matches are returned.
<a name="line60"></a> * @param {Function} rowFilter A function(rows) that returns an array of rows as
<a name="line61"></a> *     a subset of the rows input array.
<a name="line62"></a> */
<a name="line63"></a>goog.ui.ac.RichRemoteArrayMatcher.prototype.setRowFilter = function(rowFilter) {
<a name="line64"></a>  this.rowFilter_ = rowFilter;
<a name="line65"></a>};
<a name="line66"></a>
<a name="line67"></a>
<a name="line68"></a>/**
<a name="line69"></a> * Retrieve a set of matching rows from the server via ajax and convert them
<a name="line70"></a> * into rich rows.
<a name="line71"></a> * @param {string} token The text that should be matched; passed to the server
<a name="line72"></a> *     as the &#39;token&#39; query param.
<a name="line73"></a> * @param {number} maxMatches The maximum number of matches requested from the
<a name="line74"></a> *     server; passed as the &#39;max_matches&#39; query param. The server is
<a name="line75"></a> *     responsible for limiting the number of matches that are returned.
<a name="line76"></a> * @param {Function} matchHandler Callback to execute on the result after
<a name="line77"></a> *     matching.
<a name="line78"></a> * @override
<a name="line79"></a> */
<a name="line80"></a>goog.ui.ac.RichRemoteArrayMatcher.prototype.requestMatchingRows =
<a name="line81"></a>    function(token, maxMatches, matchHandler) {
<a name="line82"></a>  // The RichRemoteArrayMatcher must map over the results and filter them
<a name="line83"></a>  // before calling the request matchHandler.  This is done by passing
<a name="line84"></a>  // myMatchHandler to RemoteArrayMatcher.requestMatchingRows which maps,
<a name="line85"></a>  // filters, and then calls matchHandler.
<a name="line86"></a>  var myMatchHandler = goog.bind(function(token, matches) {
<a name="line87"></a>    /** @preserveTry */
<a name="line88"></a>    try {
<a name="line89"></a>      var rows = [];
<a name="line90"></a>      for (var i = 0; i &lt; matches.length; i++) {
<a name="line91"></a>        var func =  /** @type {!Function} */
<a name="line92"></a>            (goog.json.unsafeParse(matches[i][0]));
<a name="line93"></a>        for (var j = 1; j &lt; matches[i].length; j++) {
<a name="line94"></a>          var richRow = func(matches[i][j]);
<a name="line95"></a>          rows.push(richRow);
<a name="line96"></a>
<a name="line97"></a>          // If no render function was provided, set the node&#39;s innerHTML.
<a name="line98"></a>          if (typeof richRow.render == &#39;undefined&#39;) {
<a name="line99"></a>            richRow.render = function(node, token) {
<a name="line100"></a>              node.innerHTML = richRow.toString();
<a name="line101"></a>            };
<a name="line102"></a>          }
<a name="line103"></a>
<a name="line104"></a>          // If no select function was provided, set the text of the input.
<a name="line105"></a>          if (typeof richRow.select == &#39;undefined&#39;) {
<a name="line106"></a>            richRow.select = function(target) {
<a name="line107"></a>              target.value = richRow.toString();
<a name="line108"></a>            };
<a name="line109"></a>          }
<a name="line110"></a>        }
<a name="line111"></a>      }
<a name="line112"></a>      if (this.rowFilter_) {
<a name="line113"></a>        rows = this.rowFilter_(rows);
<a name="line114"></a>      }
<a name="line115"></a>      matchHandler(token, rows);
<a name="line116"></a>    } catch (exception) {
<a name="line117"></a>      // TODO(user): Is this what we want?
<a name="line118"></a>      matchHandler(token, []);
<a name="line119"></a>    }
<a name="line120"></a>  }, this);
<a name="line121"></a>
<a name="line122"></a>  // Call the super&#39;s requestMatchingRows with myMatchHandler
<a name="line123"></a>  goog.ui.ac.RichRemoteArrayMatcher.superClass_
<a name="line124"></a>      .requestMatchingRows.call(this, token, maxMatches, myMatchHandler);
<a name="line125"></a>};
</pre>


</body>
</html>
